<template>
	<view>
		<view class="u-page">
			<!-- 所有内容的容器 -->
		</view>
		<u-tabbar :inactiveColor="'#8D8D8D'" :activeColor="'#3291F8'" v-model="current" :list="list"></u-tabbar>
	</view>
</template>

<script>
	export default {
		name: "userTabbar",
		data() {
			return {
				list: [{
						iconPath: "/static/image/tabbar/home.png",
						selectedIconPath: "/static/image/tabbar/enosel.png",
						text: '首页',
						customIcon: true,
						pagePath: "/pages/economicPage/home/index"
					},
					{
						iconPath: "/static/image/tabbar/chat.png",
						selectedIconPath: "/static/image/tabbar/enoMsgSel.png",
						text: '消息',
						customIcon: true,
						pagePath: "/pages/chat/index"
					}
				],
				current: 0
			}
		},
		computed: {
			unreadCount() {
				let count = 0;
				this.chatStore.chats.forEach(chat => {
					if (!chat.delete) {
						count += chat.unreadCount;
					}
				})
				return count;
			},
			readSum(){
				return this.chatStore.readSum
			},
		},
		watch: {
			unreadCount(newCount, oldCount) {
				this.refreshUnreadBadge();
			},
			readSum(newCount, oldCount){
				this.refreshUnreadBadge()
			}
		},
		mounted() {
			this.refreshUnreadBadge()
		},
		methods: {
			async refreshUnreadBadge() {
				let data = await this.chatStore.sysNoRead()
				if (this.unreadCount > 0) {
					this.list[1].count = this.unreadCount + data.num;
				} else {
					let count = data.num > 0 ? data.num : ''
					this.list[1].count = '' + count
				}
			},
		}
	}
</script>